<?php
/**
 * Medical Center Partner Documents
 *
 * @author Xavier VILAIN
 * @package Nawa\MedicalStudy\MedicalCenter\Partner
 * @license
 */
use Fox\Behaviors;
use Nawa\MedicalStudy\MedicalCenter;
use Fox\Generator;
use Fox\Html\Button;

$xview = Xview::instance();
$msid = $xview->val('msid');
$mcid = $xview->val('mcid');
$inlineid = "$msid:$mcid";
// Load Documents
$medicalCenterPartner = \Fox\Dao::load(MedicalCenter::className(),$inlineid);
$documents = $medicalCenterPartner->documents();
// Grid
/* @var $grid \Fox\Grid */
$grid = $xview->component('medicalstudies','documents');
$genDoc = Generator::url('medicalstudies','medicalcenters', 'documents',
							array('msid' => $msid,'mcid' => $mcid));
$grid->source($genDoc);

// Delete Document action
$grid->fieldcat()->field('idele')->renderer()->behaviors(
	Behaviors::action(
		Generator::url('medicalstudies','documents','delete',
						array(	'msid' => $msid,
								'mcid' => $mcid,
								'docid' => Generator::useAttribute('docid'))
					),
		true,
		null,
		null,
		true
));

// Additionnal Action
$grid->footer()->add(new Button('add',Generator::display('addDocument',Generator::url('documents','upload',null,
array('classname' => addslashes(MedicalCenter::className()),
							  'inlineid' => $inlineid)))));
$grid->initialize($documents);
if($xview->ajax())
{
	echo $grid->display();
}
else
{
	return $grid;
}